package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;

import Background.Contestant;
import Background.Lists;

/**
 * A class to display the registration window in the gui.  Builds the window and displays it.
 * 
 * @author Chris Petcher
 * @version 27 February, 2013
 *
 */

@SuppressWarnings("serial")
public class SelectWinnersGUI extends JFrame{

	/**
	 * A dimension used in setting the size of the frame.
	 */
	
	private static final Dimension MY_SIZE = new Dimension(1000, 500);
	
	/**
	 * A dimension used for setting the size of each button.
	 */
	
	private static final Dimension MY_BUTTON_SIZE = new Dimension(100, 100);
	
	/**
	 * A panel for the judges to select the winning entries submitted by a contestant.
	 */
	
	private JPanel winner_selection_panel;
	
	/**
	 * A scroll pane for the panel to sit in.
	 */
	
	private JScrollPane scrollPane;
	
	/**
	 * An arrayList to hold the list of contestants.  Judges will select winners from this list.
	 */
	
	private ArrayList<Contestant> contestantList;
	
	/**
	 * Constructor for the SubmitEntryGUI.  Sets up the panels for use in the entry submission
	 * process.
	 */
	
	public SelectWinnersGUI() {
		 
	    super("Select the contest winners");
		
	  }

	/**
	 * 	Method that brings up the select winners gui.
	 */
		public void start() {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		    setVisible(true);
		    setSize(MY_SIZE);
		    setResizable(false);
		    winner_selection_panel = new JPanel();
		    scrollPane = new JScrollPane(winner_selection_panel);
		    add(scrollPane);
		    contestantList = Lists.getContestantList();
		    createWinnerSelections();
		    validate();
		}
		
		private void createWinnerSelections(){
			for(final Contestant c : contestantList){
				JButton contestantButton = new JButton("Name: " + c.getName() + 
						" Registration Number: " + c.getRegistrationNumber());
				winner_selection_panel.add(contestantButton);
				
				contestantButton.addActionListener(new ActionListener()

		        {
		          @Override
				public void actionPerformed(final ActionEvent the_event)
		        
		          {
		        	  Lists.addWinner(c);
		          }

		        });
				
			}
		}
}
